{% extends "base.html" %}
{% load humanize %}
{% load static %}
{% get_static_prefix as STATIC_PREFIX %}

{% block header %}
	<h1><a href='{% url worker_portal %}'>IT Support</a></h1>
	<h2>Worker View</h2>
{% endblock %}

{% block menu %}
	<a class='nav' title='Resolved Tickets' href='{% url worker_portal_status t_status=3 %}'>
		<span class='button'>Resolved</span>
	</a>
	<a class='nav' title='Closed Tickets' href='{% url worker_portal_status t_status=4 %}'>
		<span class='button'>Closed</span>
	</a>
{% endblock %}

{% block body %}

<div id='left-pane'>
	<div id='ticket-list'>
		<h1>Tickets</h1>
	{% for ticket in ticket_list %}
		<div class='{% cycle 'odd' 'even' %}' onclick="location.href='{% url worker_portal_ticket ticket_id=ticket.id %}';">
			<img src='{{ STATIC_PREFIX }}img/status/{{ ticket.status }}.png' title='{{ ticket.get_status_display }}'>
			<a href="{% url worker_portal_ticket ticket_id=ticket.id %}">{{ ticket.title }}</a>
		</div>
	{% empty %}
		No Tickets in the system
	{% endfor %}
	</div>
</div>

<div id='center-pane'>
	<div id='ticket-section'>
		<div class='ticket-dates-status'>
			<h1>Status</h1> 
			{{ ticket_detail.get_status_display }}
			<hr>
			<h1>Priority</h1> 
			{% if ticket.priority != 1 %}
				<a href='{% url worker_lower_priority ticket_id=ticket_detail.id %}'>
					<img src='{{ STATIC_PREFIX }}img/arrow_down.png'>
				</a>
			{% endif %}
			{{ ticket_detail.get_priority_display }}
			{% if ticket.priority != 5 %}
				<a href='{% url worker_raise_priority ticket_id=ticket_detail.id %}'>
					<img src='{{ STATIC_PREFIX }}img/arrow_up.png'>
				</a>
			{% endif %}
			<hr>
			<h1>Dates</h1>
			<span title='{{ ticket_detail.created }}'>Created: {{ ticket_detail.created|naturalday }}<br /></span>
			<span title='{{ ticket_detail.modified }}'>Modified: {{ ticket_detail.modified|naturalday }}</span>
		</div>
		{% if ticket_detail.status != 4 and ticket_detail.status != 3 %}
			<div class='ticket-modify close-ticket'>
				<a href='{% url worker_ticket_close ticket_id=ticket_detail.id %}'>Close Ticket</a>
			</div>
		{% endif %}
		{% if ticket_detail.status != 4 and ticket_detail.status != 3 %}
			<div class='ticket-modify resolve-ticket'>
				<a href='{% url worker_ticket_resolve ticket_id=ticket_detail.id %}'>Resolve Ticket</a>
			</div>
		{% endif %}
		{% if ticket_detail.status == 1 %}
			<div class='ticket-modify hold-ticket'>
				<a href='{% url worker_ticket_hold ticket_id=ticket_detail.id %}'>Put Ticket On-Hold</a>
			</div>
		{% endif %}
		{% if ticket_detail.status == 2 %}
			<div class='ticket-modify hold-ticket'>
				<a href='{% url worker_ticket_unhold ticket_id=ticket_detail.id %}'>Take Ticket Off Hold</a>
			</div>
		{% endif %}
		{% if ticket_detail.status == 4 or ticket_detail.status == 3 %}
			<div class='ticket-modify re-open-ticket'>
				<a href='{% url worker_ticket_reopen ticket_id=ticket_detail.id %}'>Re-Open Ticket</a>
			</div>
		{% endif %}
		<h1>{{ ticket_detail.title }}</h1>
		{{ ticket_detail.description|urlize|linebreaks }}
	</div>

	<h1>Notes</h1>
	<div id='notes-section'>
		{% if ticket_detail.note_set.all %}
			{% for note in ticket_detail.note_set.all %}
				<div class='notes-row {% cycle 'odd' 'even' %}' >
					<img class='notes-img' src='{{ STATIC_PREFIX }}img/action/{{ note.action }}.png' title='{{ note.get_action_display }}'>
					<span class='notes-date' title='{{ note.date }}'>{{ note.date|naturalday }}</span>
					<span class='notes-email'>{{ note.submitter_email }}</span><br />
					<span class='notes-comment'>{{ note.comment|urlize|linebreaks }}</span>
				</div>
			{% endfor %}
		{% else %}
			No Notes Entered
		{% endif %}
	</div>

	{% if form %}
		<div class='form-box'>
			<div class='form-title'>Add Note</div>
			<form method='POST' action='{% url worker_add_note ticket_id=ticket_detail.id %}'>
				{% csrf_token %}
				{{ form.as_p }}
				<input type="submit" value="Create Note" />
			</form>
		</div>
	{% endif %}
</div>


{% endblock %}
